import java.util.logging.Logger;

/**
 * SingletonPattern
 */
public class SingletonPattern {
    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 20; i++) {
            new Thread(() -> {
                Logger.getGlobal().info(Singleton.get().toString());
            }).start();
        }
    }
}

class Singleton {
    volatile static Singleton ins;

    static Singleton get() {
        if (ins != null) {
            return ins;
        }
        synchronized (Singleton.class) {
            if (ins != null) {
                return ins;
            }
            return (ins = new Singleton());
        }
    }
}
